Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: mojo/public/cpp/bindings/lib/validation_errors.cc

Issue 307353009: Mojo cpp bindings: report the reason of validation failure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
6
7 #include <assert.h>
8 #include <stdio.h>
9
10 namespace mojo {
11 namespace internal {
12 namespace {
13
14 ValidationErrorObserverForTesting* g_validation_error_observer = NULL;
15
16 } // namespace
17
18 const char* ValidationErrorToString(ValidationError error) {
19 switch (error) {
20 case VALIDATION_ERROR_NONE:
21 return "VALIDATION_ERROR_NONE";
22 case VALIDATION_ERROR_MISALIGNED_OBJECT:
23 return "VALIDATION_ERROR_MISALIGNED_OBJECT";
24 case VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE:
25 return "VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE";
26 case VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER:
27 return "VALIDATION_ERROR_UNEXPECTED_STRUCT_HEADER";
28 case VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER:
29 return "VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER";
30 case VALIDATION_ERROR_ILLEGAL_HANDLE:
31 return "VALIDATION_ERROR_ILLEGAL_HANDLE";
32 case VALIDATION_ERROR_ILLEGAL_POINTER:
33 return "VALIDATION_ERROR_ILLEGAL_POINTER";
34 case VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAG_COMBINAION:
35 return "VALIDATION_ERROR_MESSAGE_HEADER_INVALID_FLAG_COMBINAION";
36 case VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID:
37 return "VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID";
38 }
39
40 return "Unknown error";
41 }
42
43 void ReportValidationError(ValidationError error) {
44 // TODO(yzshen): Consider adding better logging support.
45 fprintf(stderr, "Invalid message: %s\n", ValidationErrorToString(error));
46 if (g_validation_error_observer)
47 g_validation_error_observer->set_last_error(error);
48 }
49
50 ValidationErrorObserverForTesting::ValidationErrorObserverForTesting()
51 : last_error_(VALIDATION_ERROR_NONE) {
52 assert(!g_validation_error_observer);
53 g_validation_error_observer = this;
54 }
55
56 ValidationErrorObserverForTesting::~ValidationErrorObserverForTesting() {
57 assert(g_validation_error_observer == this);
58 g_validation_error_observer = NULL;
59 }
60
61 } // namespace internal
62 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_errors.h ('k') | mojo/public/cpp/bindings/tests/validation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698