diff options
author | Marco Poletti <poletti.marco@gmail.com> | 2015-02-01 14:56:43 +0100 |
---|---|---|
committer | Marco Poletti <poletti.marco@gmail.com> | 2015-02-01 14:56:43 +0100 |
commit | 853205caf090d4823c6c766782e53f611082e9b7 (patch) | |
tree | 0c06818fdafb5fda5363e390b2213c6eb0f7f15e /tests/util | |
parent | 7e3052d565c23399061c8bbb6bd95b6ed234a228 (diff) | |
download | google-fruit-853205caf090d4823c6c766782e53f611082e9b7.tar.gz |
Add unit tests for LambdaInvoker.
Diffstat (limited to 'tests/util')
-rw-r--r-- | tests/util/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/util/lambda_invoker.cpp | 61 |
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt new file mode 100644 index 0000000..08dfa80 --- /dev/null +++ b/tests/util/CMakeLists.txt @@ -0,0 +1,5 @@ +set(UTIL_TEST_SOURCES +lambda_invoker.cpp +) + +add_fruit_tests(util UTIL_TEST_SOURCES) diff --git a/tests/util/lambda_invoker.cpp b/tests/util/lambda_invoker.cpp new file mode 100644 index 0000000..0af76f5 --- /dev/null +++ b/tests/util/lambda_invoker.cpp @@ -0,0 +1,61 @@ +// expect-success +/* + * Copyright 2014 Google Inc. All rights reserved. + * + * 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. + */ + +#define IN_FRUIT_CPP_FILE + +#include <fruit/impl/util/lambda_invoker.h> + +#include <cassert> + +using namespace std; +using namespace fruit::impl; + + +void test_invoke_no_args() { + // This is static because the lambda must have no captures. + static int num_invocations = 0; + + auto l = []() { + ++num_invocations; + }; + using L = decltype(l); + LambdaInvoker::invoke<L>(); + assert(num_invocations == 1); +} + +void test_invoke_some_args() { + // This is static because the lambda must have no captures. + static int num_invocations = 0; + + auto l = [](int n, double x) { + assert(n == 5); + assert(x == 3.14); + ++num_invocations; + }; + using L = decltype(l); + LambdaInvoker::invoke<L>(5, 3.14); + assert(num_invocations == 1); +} + + +int main() { + + test_invoke_no_args(); + test_invoke_some_args(); + + return 0; +} |