Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
grn-test-memcached-assertions.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License version 2.1 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include <gcutter.h>
21 
22 static const gchar *
23 grn_memcached_rc_to_string(memcached_return rc)
24 {
25  switch (rc) {
26  case MEMCACHED_SUCCESS:
27  return "MEMCACHED_SUCCESS";
28  case MEMCACHED_FAILURE:
29  return "MEMCACHED_FAILURE";
30  case MEMCACHED_HOST_LOOKUP_FAILURE:
31  return "MEMCACHED_HOST_LOOKUP_FAILURE";
32  case MEMCACHED_CONNECTION_FAILURE:
33  return "MEMCACHED_CONNECTION_FAILURE";
34  case MEMCACHED_CONNECTION_BIND_FAILURE:
35  return "MEMCACHED_CONNECTION_BIND_FAILURE";
36  case MEMCACHED_WRITE_FAILURE:
37  return "MEMCACHED_WRITE_FAILURE";
38  case MEMCACHED_READ_FAILURE:
39  return "MEMCACHED_READ_FAILURE";
40  case MEMCACHED_UNKNOWN_READ_FAILURE:
41  return "MEMCACHED_UNKNOWN_READ_FAILURE";
42  case MEMCACHED_PROTOCOL_ERROR:
43  return "MEMCACHED_PROTOCOL_ERROR";
44  case MEMCACHED_CLIENT_ERROR:
45  return "MEMCACHED_CLIENT_ERROR";
46  case MEMCACHED_SERVER_ERROR:
47  return "MEMCACHED_SERVER_ERROR";
48  case MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE:
49  return "MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE";
50  case MEMCACHED_DATA_EXISTS:
51  return "MEMCACHED_DATA_EXISTS";
52  case MEMCACHED_DATA_DOES_NOT_EXIST:
53  return "MEMCACHED_DATA_DOES_NOT_EXIST";
54  case MEMCACHED_NOTSTORED:
55  return "MEMCACHED_NOTSTORED";
56  case MEMCACHED_STORED:
57  return "MEMCACHED_STORED";
58  case MEMCACHED_NOTFOUND:
59  return "MEMCACHED_NOTFOUND";
60  case MEMCACHED_MEMORY_ALLOCATION_FAILURE:
61  return "MEMCACHED_MEMORY_ALLOCATION_FAILURE";
62  case MEMCACHED_PARTIAL_READ:
63  return "MEMCACHED_PARTIAL_READ";
64  case MEMCACHED_SOME_ERRORS:
65  return "MEMCACHED_SOME_ERRORS";
66  case MEMCACHED_NO_SERVERS:
67  return "MEMCACHED_NO_SERVERS";
68  case MEMCACHED_END:
69  return "MEMCACHED_END";
70  case MEMCACHED_DELETED:
71  return "MEMCACHED_DELETED";
72  case MEMCACHED_VALUE:
73  return "MEMCACHED_VALUE";
74  case MEMCACHED_STAT:
75  return "MEMCACHED_STAT";
76  case MEMCACHED_ITEM:
77  return "MEMCACHED_ITEM";
78  case MEMCACHED_ERRNO:
79  return "MEMCACHED_ERRNO";
80  case MEMCACHED_FAIL_UNIX_SOCKET:
81  return "MEMCACHED_FAIL_UNIX_SOCKET";
82  case MEMCACHED_NOT_SUPPORTED:
83  return "MEMCACHED_NOT_SUPPORTED";
84  case MEMCACHED_NO_KEY_PROVIDED:
85  return "MEMCACHED_NO_KEY_PROVIDED";
86  case MEMCACHED_FETCH_NOTFINISHED:
87  return "MEMCACHED_FETCH_NOTFINISHED";
88  case MEMCACHED_TIMEOUT:
89  return "MEMCACHED_TIMEOUT";
90  case MEMCACHED_BUFFERED:
91  return "MEMCACHED_BUFFERED";
92  case MEMCACHED_BAD_KEY_PROVIDED:
93  return "MEMCACHED_BAD_KEY_PROVIDED";
94  case MEMCACHED_INVALID_HOST_PROTOCOL:
95  return "MEMCACHED_INVALID_HOST_PROTOCOL";
96  case MEMCACHED_SERVER_MARKED_DEAD:
97  return "MEMCACHED_SERVER_MARKED_DEAD";
98  case MEMCACHED_UNKNOWN_STAT_KEY:
99  return "MEMCACHED_UNKNOWN_STAT_KEY";
100  case MEMCACHED_E2BIG:
101  return "MEMCACHED_E2BIG";
102  default:
103  return "MEMCACHED_UNKNOWN_STATUS";
104  }
105 }
106 
107 void
108 grn_test_memcached_assert_helper(memcached_return rc, const gchar *expression)
109 {
110  if (rc == MEMCACHED_SUCCESS) {
111  cut_test_pass();
112  } else {
113  cut_test_fail(cut_take_printf("expected: <%s> == MEMCACHED_SUCCESS\n"
114  " but was: <%s>",
115  expression,
116  grn_memcached_rc_to_string(rc)));
117  }
118 }
119 
120 void
122  memcached_return actual,
123  const gchar *expression_expected,
124  const gchar *expression_actual)
125 {
126  if (expected == actual) {
127  cut_test_pass();
128  } else {
129  cut_test_fail(cut_take_printf("<%s> == <%s>\n"
130  "expected: <%s>\n"
131  " but was: <%s>",
132  expression_expected,
133  expression_actual,
134  grn_memcached_rc_to_string(expected),
135  grn_memcached_rc_to_string(actual)));
136  }
137 }