OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/public/cpp/application/application_impl.h" | 5 #include "mojo/public/cpp/application/application_impl.h" |
6 #include "mojo/public/cpp/application/application_test_base.h" | 6 #include "mojo/public/cpp/application/application_test_base.h" |
7 #include "mojo/public/cpp/system/macros.h" | 7 #include "mojo/public/cpp/system/macros.h" |
8 #include "mojo/public/interfaces/bindings/tests/versioning_test_client.mojom.h" | 8 #include "mojo/public/interfaces/bindings/tests/versioning_test_client.mojom.h" |
9 | 9 |
10 namespace mojo { | 10 namespace mojo { |
(...skipping 27 matching lines...) Expand all Loading... |
38 employee->employee_id = 1; | 38 employee->employee_id = 1; |
39 employee->name = "Homer Simpson"; | 39 employee->name = "Homer Simpson"; |
40 employee->department = DEPARTMENT_DEV; | 40 employee->department = DEPARTMENT_DEV; |
41 | 41 |
42 database_->QueryEmployee(1, true, | 42 database_->QueryEmployee(1, true, |
43 [&employee](EmployeePtr returned_employee, | 43 [&employee](EmployeePtr returned_employee, |
44 Array<uint8_t> returned_finger_print) { | 44 Array<uint8_t> returned_finger_print) { |
45 EXPECT_TRUE(employee->Equals(*returned_employee)); | 45 EXPECT_TRUE(employee->Equals(*returned_employee)); |
46 EXPECT_FALSE(returned_finger_print.is_null()); | 46 EXPECT_FALSE(returned_finger_print.is_null()); |
47 }); | 47 }); |
48 database_.WaitForIncomingMethodCall(); | 48 database_.WaitForIncomingResponse(); |
49 | 49 |
50 // Passing a struct of older version to the service side works. | 50 // Passing a struct of older version to the service side works. |
51 EmployeePtr new_employee(Employee::New()); | 51 EmployeePtr new_employee(Employee::New()); |
52 new_employee->employee_id = 2; | 52 new_employee->employee_id = 2; |
53 new_employee->name = "Marge Simpson"; | 53 new_employee->name = "Marge Simpson"; |
54 new_employee->department = DEPARTMENT_SALES; | 54 new_employee->department = DEPARTMENT_SALES; |
55 | 55 |
56 database_->AddEmployee(new_employee.Clone(), | 56 database_->AddEmployee(new_employee.Clone(), |
57 [](bool success) { EXPECT_TRUE(success); }); | 57 [](bool success) { EXPECT_TRUE(success); }); |
58 database_.WaitForIncomingMethodCall(); | 58 database_.WaitForIncomingResponse(); |
59 | 59 |
60 database_->QueryEmployee( | 60 database_->QueryEmployee( |
61 2, false, [&new_employee](EmployeePtr returned_employee, | 61 2, false, [&new_employee](EmployeePtr returned_employee, |
62 Array<uint8_t> returned_finger_print) { | 62 Array<uint8_t> returned_finger_print) { |
63 EXPECT_TRUE(new_employee->Equals(*returned_employee)); | 63 EXPECT_TRUE(new_employee->Equals(*returned_employee)); |
64 EXPECT_TRUE(returned_finger_print.is_null()); | 64 EXPECT_TRUE(returned_finger_print.is_null()); |
65 }); | 65 }); |
66 database_.WaitForIncomingMethodCall(); | 66 database_.WaitForIncomingResponse(); |
67 } | 67 } |
68 | 68 |
69 TEST_F(VersioningApplicationTest, QueryVersion) { | 69 TEST_F(VersioningApplicationTest, QueryVersion) { |
70 EXPECT_EQ(0u, database_.version()); | 70 EXPECT_EQ(0u, database_.version()); |
71 database_.QueryVersion([](uint32_t version) { EXPECT_EQ(1u, version); }); | 71 database_.QueryVersion([](uint32_t version) { EXPECT_EQ(1u, version); }); |
72 database_.WaitForIncomingMethodCall(); | 72 database_.WaitForIncomingResponse(); |
73 EXPECT_EQ(1u, database_.version()); | 73 EXPECT_EQ(1u, database_.version()); |
74 } | 74 } |
75 | 75 |
76 TEST_F(VersioningApplicationTest, RequireVersion) { | 76 TEST_F(VersioningApplicationTest, RequireVersion) { |
77 EXPECT_EQ(0u, database_.version()); | 77 EXPECT_EQ(0u, database_.version()); |
78 | 78 |
79 database_.RequireVersion(1); | 79 database_.RequireVersion(1); |
80 EXPECT_EQ(1u, database_.version()); | 80 EXPECT_EQ(1u, database_.version()); |
81 database_->QueryEmployee(3, false, | 81 database_->QueryEmployee(3, false, |
82 [](EmployeePtr returned_employee, | 82 [](EmployeePtr returned_employee, |
83 Array<uint8_t> returned_finger_print) {}); | 83 Array<uint8_t> returned_finger_print) {}); |
84 database_.WaitForIncomingMethodCall(); | 84 database_.WaitForIncomingResponse(); |
85 EXPECT_FALSE(database_.encountered_error()); | 85 EXPECT_FALSE(database_.encountered_error()); |
86 | 86 |
87 // Requiring a version higher than what the service side implements will close | 87 // Requiring a version higher than what the service side implements will close |
88 // the pipe. | 88 // the pipe. |
89 database_.RequireVersion(3); | 89 database_.RequireVersion(3); |
90 EXPECT_EQ(3u, database_.version()); | 90 EXPECT_EQ(3u, database_.version()); |
91 database_->QueryEmployee(1, false, | 91 database_->QueryEmployee(1, false, |
92 [](EmployeePtr returned_employee, | 92 [](EmployeePtr returned_employee, |
93 Array<uint8_t> returned_finger_print) {}); | 93 Array<uint8_t> returned_finger_print) {}); |
94 database_.WaitForIncomingMethodCall(); | 94 database_.WaitForIncomingResponse(); |
95 EXPECT_TRUE(database_.encountered_error()); | 95 EXPECT_TRUE(database_.encountered_error()); |
96 } | 96 } |
97 | 97 |
98 TEST_F(VersioningApplicationTest, CallNonexistentMethod) { | 98 TEST_F(VersioningApplicationTest, CallNonexistentMethod) { |
99 EXPECT_EQ(0u, database_.version()); | 99 EXPECT_EQ(0u, database_.version()); |
100 | 100 |
101 Array<uint8_t> new_finger_print(128); | 101 Array<uint8_t> new_finger_print(128); |
102 for (size_t i = 0; i < 128; ++i) | 102 for (size_t i = 0; i < 128; ++i) |
103 new_finger_print[i] = i + 13; | 103 new_finger_print[i] = i + 13; |
104 | 104 |
105 // Although the client side doesn't know whether the service side supports | 105 // Although the client side doesn't know whether the service side supports |
106 // version 1, calling a version 1 method succeeds as long as the service side | 106 // version 1, calling a version 1 method succeeds as long as the service side |
107 // supports version 1. | 107 // supports version 1. |
108 database_->AttachFingerPrint(1, new_finger_print.Clone(), | 108 database_->AttachFingerPrint(1, new_finger_print.Clone(), |
109 [](bool success) { EXPECT_TRUE(success); }); | 109 [](bool success) { EXPECT_TRUE(success); }); |
110 database_.WaitForIncomingMethodCall(); | 110 database_.WaitForIncomingResponse(); |
111 | 111 |
112 // Calling a version 2 method (which the service side doesn't support) closes | 112 // Calling a version 2 method (which the service side doesn't support) closes |
113 // the pipe. | 113 // the pipe. |
114 database_->ListEmployeeIds([](Array<uint64_t> ids) { EXPECT_TRUE(false); }); | 114 database_->ListEmployeeIds([](Array<uint64_t> ids) { EXPECT_TRUE(false); }); |
115 database_.WaitForIncomingMethodCall(); | 115 database_.WaitForIncomingResponse(); |
116 EXPECT_TRUE(database_.encountered_error()); | 116 EXPECT_TRUE(database_.encountered_error()); |
117 } | 117 } |
118 | 118 |
119 } // namespace versioning | 119 } // namespace versioning |
120 } // namespace examples | 120 } // namespace examples |
121 } // namespace mojo | 121 } // namespace mojo |
OLD | NEW |