• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_TESTS_VARIANT_TEST_UTIL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_TESTS_VARIANT_TEST_UTIL_H_
7 
8 #include <string.h>
9 
10 #include "base/logging.h"
11 #include "mojo/public/cpp/bindings/interface_request.h"
12 
13 namespace mojo {
14 namespace test {
15 
16 // Converts a request of Interface1 to a request of Interface0. Interface0 and
17 // Interface1 are expected to be two variants of the same mojom interface.
18 // In real-world use cases, users shouldn't need to worry about this. Because it
19 // is rare to deal with two variants of the same interface in the same app.
20 template <typename Interface0, typename Interface1>
ConvertInterfaceRequest(InterfaceRequest<Interface1> request)21 InterfaceRequest<Interface0> ConvertInterfaceRequest(
22     InterfaceRequest<Interface1> request) {
23   DCHECK_EQ(0, strcmp(Interface0::Name_, Interface1::Name_));
24   InterfaceRequest<Interface0> result;
25   result.Bind(request.PassMessagePipe());
26   return result;
27 }
28 
29 }  // namespace test
30 }  // namespace mojo
31 
32 #endif  // MOJO_PUBLIC_CPP_BINDINGS_TESTS_VARIANT_TEST_UTIL_H_
33