Motr  M0
str.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #include "net/test/str.h"
24 #include "lib/vec.h" /* m0_bufvec */
25 #include "lib/memory.h" /* m0_free0 */
26 #include "ut/ut.h"
27 
28 enum {
29  STR_BUF_LEN = 0x100,
31 };
32 
33 static void try_serialize(char *str)
34 {
35  char buf[STR_BUF_LEN];
36  void *addr = buf;
37  m0_bcount_t buf_len = STR_BUF_LEN;
38  struct m0_bufvec bv = M0_BUFVEC_INIT_BUF(&addr, &buf_len);
39  m0_bcount_t serialized_len;
40  m0_bcount_t len;
41  char *str2;
42  int str_len;
43  int rc;
44 
46  &str, &bv, STR_BUF_OFFSET);
47  M0_UT_ASSERT(serialized_len > 0);
48 
49  str2 = NULL;
51  &str2, &bv, STR_BUF_OFFSET);
52  M0_UT_ASSERT(len == serialized_len);
53 
54  str_len = strlen(str);
55  rc = strncmp(str, str2, str_len + 1);
56  M0_UT_ASSERT(rc == 0);
57  m0_free0(&str2);
58 }
59 
61 {
62  try_serialize("");
63  try_serialize("asdf");
64  try_serialize("SGVsbG8sIHdvcmxkIQo=");
65  try_serialize("0123456789!@#$%^&*()qwertyuiopasdfghjklzxcvbnm"
66  "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
67  try_serialize(__FILE__);
68 }
69 
70 /*
71  * Local variables:
72  * c-indentation-style: "K&R"
73  * c-basic-offset: 8
74  * tab-width: 8
75  * fill-column: 79
76  * scroll-step: 1
77  * End:
78  */
#define M0_BUFVEC_INIT_BUF(addr_ptr, count_ptr)
Definition: vec.h:165
#define NULL
Definition: misc.h:38
uint64_t m0_bcount_t
Definition: types.h:77
static int void * buf
Definition: dir.c:1019
Definition: sock.c:887
#define m0_free0(pptr)
Definition: memory.h:77
Definition: xcode.h:73
m0_bcount_t m0_net_test_str_serialize(enum m0_net_test_serialize_op op, char **str, struct m0_bufvec *bv, m0_bcount_t bv_offset)
Definition: str.c:57
static void try_serialize(char *str)
Definition: str.c:33
void m0_net_test_str_ut(void)
Definition: str.c:60
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
Definition: vec.h:145