Remove building with NOCRYPTO option
[minix3.git] / external / bsd / kyua-cli / dist / utils / config / keys_test.cpp
bloba73726546ff623a27af01879454af5841009b034
1 // Copyright 2012 Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "utils/config/keys.hpp"
31 #include <atf-c++.hpp>
33 #include "utils/config/exceptions.hpp"
35 namespace config = utils::config;
38 ATF_TEST_CASE_WITHOUT_HEAD(flatten_key__one);
39 ATF_TEST_CASE_BODY(flatten_key__one)
41 config::detail::tree_key key;
42 key.push_back("foo");
43 ATF_REQUIRE_EQ("foo", config::detail::flatten_key(key));
47 ATF_TEST_CASE_WITHOUT_HEAD(flatten_key__many);
48 ATF_TEST_CASE_BODY(flatten_key__many)
50 config::detail::tree_key key;
51 key.push_back("foo");
52 key.push_back("1");
53 key.push_back("bar");
54 ATF_REQUIRE_EQ("foo.1.bar", config::detail::flatten_key(key));
58 ATF_TEST_CASE_WITHOUT_HEAD(parse_key__one);
59 ATF_TEST_CASE_BODY(parse_key__one)
61 config::detail::tree_key exp_key;
62 exp_key.push_back("one");
63 ATF_REQUIRE(exp_key == config::detail::parse_key("one"));
67 ATF_TEST_CASE_WITHOUT_HEAD(parse_key__many);
68 ATF_TEST_CASE_BODY(parse_key__many)
70 config::detail::tree_key exp_key;
71 exp_key.push_back("one");
72 exp_key.push_back("2");
73 exp_key.push_back("foo");
74 ATF_REQUIRE(exp_key == config::detail::parse_key("one.2.foo"));
78 ATF_TEST_CASE_WITHOUT_HEAD(parse_key__empty_key);
79 ATF_TEST_CASE_BODY(parse_key__empty_key)
81 ATF_REQUIRE_THROW_RE(config::invalid_key_error,
82 "Empty key",
83 config::detail::parse_key(""));
87 ATF_TEST_CASE_WITHOUT_HEAD(parse_key__empty_component);
88 ATF_TEST_CASE_BODY(parse_key__empty_component)
90 ATF_REQUIRE_THROW_RE(config::invalid_key_error,
91 "Empty component in key '.'",
92 config::detail::parse_key("."));
93 ATF_REQUIRE_THROW_RE(config::invalid_key_error,
94 "Empty component in key 'a.'",
95 config::detail::parse_key("a."));
96 ATF_REQUIRE_THROW_RE(config::invalid_key_error,
97 "Empty component in key '.b'",
98 config::detail::parse_key(".b"));
99 ATF_REQUIRE_THROW_RE(config::invalid_key_error,
100 "Empty component in key 'a..b'",
101 config::detail::parse_key("a..b"));
105 ATF_INIT_TEST_CASES(tcs)
107 ATF_ADD_TEST_CASE(tcs, flatten_key__one);
108 ATF_ADD_TEST_CASE(tcs, flatten_key__many);
110 ATF_ADD_TEST_CASE(tcs, parse_key__one);
111 ATF_ADD_TEST_CASE(tcs, parse_key__many);
112 ATF_ADD_TEST_CASE(tcs, parse_key__empty_key);
113 ATF_ADD_TEST_CASE(tcs, parse_key__empty_component);