OSDN Git Service

Do not send AT+CHLD=? if the 3-way call feature is not supported am: 79dc36d01a
[android-x86/system-bt.git] / osi / test / future_test.cpp
1 /******************************************************************************
2  *
3  *  Copyright (C) 2014 Google, Inc.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18
19 #include <gtest/gtest.h>
20
21 #include "AllocationTestHarness.h"
22
23 extern "C" {
24 #include "osi/include/future.h"
25 #include "osi/include/osi.h"
26 #include "osi/include/thread.h"
27 }
28
29 static const char *pass_back_data0 = "fancy a sandwich? it's a fancy sandwich";
30 static const char *pass_back_data1 = "what kind of ice cream truck plays the worst christmas song of all time?";
31
32 class FutureTest : public AllocationTestHarness {};
33
34 static void post_to_future(void *context) {
35   future_ready((future_t *)context, (void *)pass_back_data0);
36 }
37
38 TEST_F(FutureTest, test_future_non_immediate) {
39   future_t *future = future_new();
40   ASSERT_TRUE(future != NULL);
41
42   thread_t *worker_thread = thread_new("worker thread");
43   thread_post(worker_thread, post_to_future, future);
44
45   EXPECT_EQ(pass_back_data0, future_await(future));
46
47   thread_free(worker_thread);
48 }
49
50 TEST_F(FutureTest, test_future_immediate) {
51   future_t *future = future_new_immediate((void *)pass_back_data1);
52   ASSERT_TRUE(future != NULL);
53   EXPECT_EQ(pass_back_data1, future_await(future));
54 }