Home | History | Annotate | Download | only in nacl_io_test
      1 // Copyright (c) 2013 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 TESTS_NACL_IO_TEST_MOCK_UTIL_H_
      6 #define TESTS_NACL_IO_TEST_MOCK_UTIL_H_
      7 
      8 #include <gmock/gmock.h>
      9 #include <ppapi/c/pp_completion_callback.h>
     10 #include <ppapi/c/pp_var.h>
     11 
     12 ACTION_TEMPLATE(CallCallback,
     13                 HAS_1_TEMPLATE_PARAMS(int, k),
     14                 AND_1_VALUE_PARAMS(result)) {
     15   PP_CompletionCallback callback = std::tr1::get<k>(args);
     16   if (callback.func) {
     17     (*callback.func)(callback.user_data, result);
     18   }
     19 }
     20 
     21 MATCHER_P(IsEqualToVar, var, "") {
     22   if (arg.type != var.type)
     23     return false;
     24 
     25   switch (arg.type) {
     26     case PP_VARTYPE_BOOL:
     27       return arg.value.as_bool == var.value.as_bool;
     28 
     29     case PP_VARTYPE_INT32:
     30       return arg.value.as_int == var.value.as_int;
     31 
     32     case PP_VARTYPE_DOUBLE:
     33       return arg.value.as_double == var.value.as_double;
     34 
     35     case PP_VARTYPE_STRING:
     36       return arg.value.as_id == var.value.as_id;
     37 
     38     case PP_VARTYPE_UNDEFINED:
     39     case PP_VARTYPE_NULL:
     40       return true;
     41 
     42     case PP_VARTYPE_ARRAY:
     43     case PP_VARTYPE_ARRAY_BUFFER:
     44     case PP_VARTYPE_DICTIONARY:
     45     case PP_VARTYPE_OBJECT:
     46     default:
     47       // Not supported.
     48       return false;
     49   }
     50 }
     51 
     52 #endif  // TESTS_NACL_IO_TEST_MOCK_UTIL_H_
     53