diff options
author | Christopher Wiley <wiley@google.com> | 2016-02-01 22:21:48 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-02-01 22:21:48 +0000 |
commit | f2bcff414a3e6ab448fad823adc216ca3050f31b (patch) | |
tree | 1c5154ac480dd254dcc67b80436139ff18d8ed40 | |
parent | e53f635da7e2b58351aaf5d954d66d2ce30fe3c8 (diff) | |
parent | c79583392abd844923ca07988754d2b9b9aefaf3 (diff) | |
download | aidl-f2bcff414a3e6ab448fad823adc216ca3050f31b.tar.gz |
Pull out helpers for testing primitives
am: c79583392a
* commit 'c79583392abd844923ca07988754d2b9b9aefaf3':
Pull out helpers for testing primitives
-rw-r--r-- | Android.mk | 3 | ||||
-rw-r--r-- | tests/aidl_test_client_primitives.cpp | 44 | ||||
-rw-r--r-- | tests/test_helpers.h | 78 |
3 files changed, 82 insertions, 43 deletions
@@ -128,6 +128,7 @@ endif # No TARGET_BUILD_APPS or TARGET_BUILD_PDK # aidl_integration_test_cflags := $(aidl_cflags) -Wunused-parameter aidl_integration_test_shared_libs := \ + libbase \ libbinder \ liblog \ libutils @@ -136,7 +137,7 @@ include $(CLEAR_VARS) LOCAL_MODULE := libaidl-integration-test LOCAL_MODULE_CLASS := SHARED_LIBRARIES LOCAL_CFLAGS := $(aidl_integration_test_cflags) -LOCAL_SHARED_LIBRARIES := $(aidl_integration_test_shared_libs) libbase +LOCAL_SHARED_LIBRARIES := $(aidl_integration_test_shared_libs) LOCAL_AIDL_INCLUDES := \ system/tools/aidl/tests/ \ frameworks/native/aidl/binder diff --git a/tests/aidl_test_client_primitives.cpp b/tests/aidl_test_client_primitives.cpp index c88b6040..1893793e 100644 --- a/tests/aidl_test_client_primitives.cpp +++ b/tests/aidl_test_client_primitives.cpp @@ -24,6 +24,8 @@ #include "android/aidl/tests/INamedCallback.h" +#include "test_helpers.h" + // libutils: using android::sp; using android::String16; @@ -46,20 +48,6 @@ namespace aidl { namespace tests { namespace client { -template <typename T> -bool RepeatPrimitive(const sp<ITestService>& service, - Status(ITestService::*func)(T, T*), - const T input) { - T reply; - Status status = (*service.*func)(input, &reply); - if (!status.isOk() || input != reply) { - cerr << "Failed to repeat primitive. status=" << status.toString8() - << "." << endl; - return false; - } - return true; -} - bool ConfirmPrimitiveRepeat(const sp<ITestService>& s) { cout << "Confirming passing and returning primitives works." << endl; @@ -108,34 +96,6 @@ bool ConfirmPrimitiveRepeat(const sp<ITestService>& s) { return true; } -template <typename T> -bool ReverseArray(const sp<ITestService>& service, - Status(ITestService::*func)(const vector<T>&, - vector<T>*, - vector<T>*), - vector<T> input) { - vector<T> actual_reversed; - vector<T> actual_repeated; - Status status = (*service.*func)(input, &actual_repeated, &actual_reversed); - if (!status.isOk()) { - cerr << "Failed to repeat array. status=" << status.toString8() << "." - << endl; - return false; - } - if (input != actual_repeated) { - cerr << "Repeated version of array did not match" << endl; - cerr << "input.size()=" << input.size() - << " repeated.size()=" << actual_repeated.size() << endl; - return false; - } - std::reverse(input.begin(), input.end()); - if (input != actual_reversed) { - cerr << "Reversed version of array did not match" << endl; - return false; - } - return true; -} - bool ConfirmReverseArrays(const sp<ITestService>& s) { cout << "Confirming passing and returning arrays works." << endl; diff --git a/tests/test_helpers.h b/tests/test_helpers.h new file mode 100644 index 00000000..638eecc2 --- /dev/null +++ b/tests/test_helpers.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2016 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 <algorithm> +#include <vector> + +#include <android-base/logging.h> +#include <binder/Status.h> +#include <utils/StrongPointer.h> + +#include "android/aidl/tests/ITestService.h" + +namespace android { +namespace aidl { +namespace tests { +namespace client { + +template <typename T> +bool RepeatPrimitive( + const android::sp<android::aidl::tests::ITestService>& service, + android::binder::Status(android::aidl::tests::ITestService::*func)(T, T*), + const T input) { + T reply; + android::binder::Status status = (*service.*func)(input, &reply); + if (!status.isOk() || input != reply) { + LOG(ERROR) << "Failed to repeat primitive. status=" << status.toString8() + << "."; + return false; + } + return true; +} + +template <typename T> +bool ReverseArray( + const android::sp<android::aidl::tests::ITestService>& service, + android::binder::Status(android::aidl::tests::ITestService::*func)( + const std::vector<T>&, std::vector<T>*, std::vector<T>*), + std::vector<T> input) { + std::vector<T> actual_reversed; + std::vector<T> actual_repeated; + android::binder::Status status = (*service.*func)( + input, &actual_repeated, &actual_reversed); + if (!status.isOk()) { + LOG(ERROR) << "Failed to repeat array. status=" << status.toString8() + << "."; + return false; + } + if (input != actual_repeated) { + LOG(ERROR) << "Repeated version of array did not match"; + LOG(ERROR) << "input.size()=" << input.size() + << " repeated.size()=" << actual_repeated.size(); + return false; + } + std::reverse(input.begin(), input.end()); + if (input != actual_reversed) { + LOG(ERROR) << "Reversed version of array did not match"; + return false; + } + return true; +} + +} // namespace client +} // namespace tests +} // namespace aidl +} // namespace android |