Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
test-text.c
Go to the documentation of this file.
1 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
2 /*
3  Copyright(C) 2009 Brazil
4  Copyright(C) 2011 Kouhei Sutou <kou@clear-code.com>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License version 2.1 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #include "str.h"
21 #include <stdio.h>
22 
23 #include <gcutter.h>
24 
25 #include "../lib/grn-assertions.h"
26 
27 void test_time2rfc1123(void);
28 void test_atoi_padded(void);
29 void test_urldec(void);
30 
31 static grn_ctx context;
32 
33 void
35 {
36 }
37 
38 void
40 {
41 }
42 
43 void
44 cut_setup(void)
45 {
46  grn_ctx_init(&context, 0);
47 }
48 
49 void
51 {
52  grn_ctx_fin(&context);
53 }
54 
55 void
57 {
58  grn_obj rfc1123;
59  const gchar *dupped_rfc1123;
60 
61  GRN_TEXT_INIT(&rfc1123, 0);
62  grn_text_time2rfc1123(&context, &rfc1123, 1243433233);
63  dupped_rfc1123 = cut_take_strndup(GRN_TEXT_VALUE(&rfc1123),
64  GRN_TEXT_LEN(&rfc1123));
65  grn_obj_unlink(&context, &rfc1123);
66  cut_assert_equal_string("Wed, 27 May 2009 14:07:13 GMT", dupped_rfc1123);
67 }
68 
69 void
71 {
72  grn_obj t;
73  GRN_TEXT_INIT(&t, 0);
74  grn_text_itoa_padded(&context, &t, 543, '*', 5);
75  cut_assert_equal_memory("**543", 5, GRN_TEXT_VALUE(&t), GRN_TEXT_LEN(&t));
76 
77  GRN_BULK_REWIND(&t);
78  grn_text_itoa_padded(&context, &t, 0, '-', 5);
79  cut_assert_equal_memory("----0", 5, GRN_TEXT_VALUE(&t), GRN_TEXT_LEN(&t));
80 
81  GRN_BULK_REWIND(&t);
82  grn_text_itoa_padded(&context, &t, -123, ' ', 5);
83  cut_assert_equal_memory("- 123", 5, GRN_TEXT_VALUE(&t), GRN_TEXT_LEN(&t));
84 
85  GRN_BULK_REWIND(&t);
86  grn_text_itoa_padded(&context, &t, 123, ' ', 0);
87  cut_assert_equal_memory("", 0, GRN_TEXT_VALUE(&t), GRN_TEXT_LEN(&t));
88 }
89 
90 void
92 {
93  grn_obj decoded_url;
94  const gchar *dupped_deocded_url;
95  const gchar *url = "/+test%20/u_hihi%00desu?yo-da:test";
96 
97  GRN_TEXT_INIT(&decoded_url, 0);
98  grn_text_urldec(&context,
99  &decoded_url,
100  url, url + strlen(url),
101  ':');
102  dupped_deocded_url = cut_take_strndup(GRN_TEXT_VALUE(&decoded_url),
103  GRN_TEXT_LEN(&decoded_url));
104  grn_obj_unlink(&context, &decoded_url);
105  cut_assert_equal_string("/+test /u_hihi\0desu?yo-da",
106  dupped_deocded_url);
107 }