diff options
-rw-r--r-- | nfc/1.0/vts/functional/Android.bp | 36 | ||||
-rw-r--r-- | nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp | 97 |
2 files changed, 133 insertions, 0 deletions
diff --git a/nfc/1.0/vts/functional/Android.bp b/nfc/1.0/vts/functional/Android.bp new file mode 100644 index 00000000..0f1afbdd --- /dev/null +++ b/nfc/1.0/vts/functional/Android.bp | |||
@@ -0,0 +1,36 @@ | |||
1 | // | ||
2 | // Copyright (C) 2016 The Android Open Source Project | ||
3 | // | ||
4 | // Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | // you may not use this file except in compliance with the License. | ||
6 | // You may obtain a copy of the License at | ||
7 | // | ||
8 | // http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | // | ||
10 | // Unless required by applicable law or agreed to in writing, software | ||
11 | // distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | // See the License for the specific language governing permissions and | ||
14 | // limitations under the License. | ||
15 | // | ||
16 | |||
17 | cc_test { | ||
18 | name: "nfc_hidl_hal_test", | ||
19 | gtest: true, | ||
20 | srcs: ["nfc_hidl_hal_test.cpp"], | ||
21 | shared_libs: [ | ||
22 | "libbase", | ||
23 | "liblog", | ||
24 | "libcutils", | ||
25 | "libhidl", | ||
26 | "libhwbinder", | ||
27 | "libnativehelper", | ||
28 | "libutils", | ||
29 | "android.hardware.nfc@1.0", | ||
30 | ], | ||
31 | static_libs: ["libgtest"], | ||
32 | cflags: [ | ||
33 | "-O0", | ||
34 | "-g", | ||
35 | ], | ||
36 | } \ No newline at end of file | ||
diff --git a/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp b/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp new file mode 100644 index 00000000..e2157046 --- /dev/null +++ b/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp | |||
@@ -0,0 +1,97 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #define LOG_TAG "nfc_hidl_hal_test" | ||
18 | #include <android-base/logging.h> | ||
19 | |||
20 | #include <hardware/nfc.h> | ||
21 | #include <android/hardware/nfc/1.0/types.h> | ||
22 | #include <android/hardware/nfc/1.0/INfc.h> | ||
23 | #include <android/hardware/nfc/1.0/INfcClientCallback.h> | ||
24 | |||
25 | #include <gtest/gtest.h> | ||
26 | |||
27 | using ::android::hardware::nfc::V1_0::INfc; | ||
28 | using ::android::hardware::nfc::V1_0::INfcClientCallback; | ||
29 | using ::android::hardware::Return; | ||
30 | using ::android::hardware::Void; | ||
31 | using ::android::sp; | ||
32 | |||
33 | #define NFC_NCI_SERVICE_NAME "nfc_nci" | ||
34 | |||
35 | |||
36 | // Simple NfcClientCallback used as part of testing. | ||
37 | class NfcClientCallback : public INfcClientCallback { | ||
38 | public: | ||
39 | NfcClientCallback() {}; | ||
40 | |||
41 | virtual ~NfcClientCallback() = default; | ||
42 | |||
43 | // sendEvent callback function - currently no-op. | ||
44 | Return<void> sendEvent( | ||
45 | ::android::hardware::nfc::V1_0::NfcEvent event, | ||
46 | ::android::hardware::nfc::V1_0::NfcStatus event_status) override { | ||
47 | return Void(); | ||
48 | }; | ||
49 | |||
50 | // sendData callback function - currently no-op. | ||
51 | Return<void> sendData(const ::android::hardware::nfc::V1_0::NfcData &data ) override { | ||
52 | ::android::hardware::nfc::V1_0::NfcData copy = data; | ||
53 | return Void(); | ||
54 | }; | ||
55 | }; | ||
56 | |||
57 | |||
58 | // The main test class for NFC HIDL HAL. | ||
59 | class NfcHidlTest : public ::testing::Test { | ||
60 | public: | ||
61 | virtual void SetUp() override { | ||
62 | // currently test passthrough mode only | ||
63 | nfc = INfc::getService(NFC_NCI_SERVICE_NAME, true); | ||
64 | ASSERT_NE(nfc, nullptr); | ||
65 | |||
66 | nfc_cb = new NfcClientCallback(); | ||
67 | ASSERT_NE(nfc_cb, nullptr); | ||
68 | } | ||
69 | |||
70 | virtual void TearDown() override {} | ||
71 | |||
72 | sp<INfc> nfc; | ||
73 | sp<INfcClientCallback> nfc_cb; | ||
74 | }; | ||
75 | |||
76 | |||
77 | // A class for test environment setup (kept since this file is a template). | ||
78 | class NfcHidlEnvironment : public ::testing::Environment { | ||
79 | public: | ||
80 | virtual void SetUp() {} | ||
81 | virtual void TearDown() {} | ||
82 | |||
83 | private: | ||
84 | }; | ||
85 | |||
86 | TEST_F(NfcHidlTest, OpenAndClose) { | ||
87 | EXPECT_EQ(0, (int)nfc->open(nfc_cb)); | ||
88 | EXPECT_EQ(0, (int)nfc->close()); | ||
89 | } | ||
90 | |||
91 | int main(int argc, char **argv) { | ||
92 | ::testing::AddGlobalTestEnvironment(new NfcHidlEnvironment); | ||
93 | ::testing::InitGoogleTest(&argc, argv); | ||
94 | int status = RUN_ALL_TESTS(); | ||
95 | ALOGI("Test result = %d", status); | ||
96 | return status; | ||
97 | } | ||