]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/common/test_str_map.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
8 * Author: Loic Dachary <loic@dachary.org>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
18 #include <gtest/gtest.h>
20 #include "include/str_map.h"
25 map
<string
,string
> str_map
;
28 ASSERT_EQ(0, get_json_str_map("{\"key\": \"value\"}", ss
, &str_map
));
29 ASSERT_EQ("value", str_map
["key"]);
30 // well formatted but not a JSON object
31 ASSERT_EQ(-EINVAL
, get_json_str_map("\"key\"", ss
, &str_map
));
32 ASSERT_NE(string::npos
, ss
.str().find("must be a JSON object"));
35 TEST(str_map
, plaintext
) {
37 map
<string
,string
> str_map
;
38 ASSERT_EQ(0, get_str_map(" foo=bar\t\nfrob=nitz yeah right= \n\t",
40 ASSERT_EQ(4u, str_map
.size());
41 ASSERT_EQ("bar", str_map
["foo"]);
42 ASSERT_EQ("nitz", str_map
["frob"]);
43 ASSERT_EQ("", str_map
["yeah"]);
44 ASSERT_EQ("", str_map
["right"]);
47 map
<string
,string
> str_map
;
48 ASSERT_EQ(0, get_str_map("that", &str_map
));
49 ASSERT_EQ(1u, str_map
.size());
50 ASSERT_EQ("", str_map
["that"]);
53 map
<string
,string
> str_map
;
54 ASSERT_EQ(0, get_str_map(" \t \n ", &str_map
));
55 ASSERT_EQ(0u, str_map
.size());
56 ASSERT_EQ(0, get_str_map("", &str_map
));
57 ASSERT_EQ(0u, str_map
.size());
60 map
<string
,string
> str_map
;
61 ASSERT_EQ(0, get_str_map(" key1=val1; key2=\tval2; key3\t = \t val3; \n ", &str_map
, "\n;"));
62 ASSERT_EQ(4u, str_map
.size());
63 ASSERT_EQ("val1", str_map
["key1"]);
64 ASSERT_EQ("val2", str_map
["key2"]);
65 ASSERT_EQ("val3", str_map
["key3"]);
71 * compile-command: "cd ../.. ; make -j4 &&
72 * make unittest_str_map &&
73 * valgrind --tool=memcheck --leak-check=full \