exceptions_test.cpp revision 1.1.1.1
1292915Sdim// Copyright 2010 Google Inc.
2292915Sdim// All rights reserved.
3292915Sdim//
4292915Sdim// Redistribution and use in source and binary forms, with or without
5292915Sdim// modification, are permitted provided that the following conditions are
6292915Sdim// met:
7292915Sdim//
8292915Sdim// * Redistributions of source code must retain the above copyright
9292915Sdim//   notice, this list of conditions and the following disclaimer.
10292915Sdim// * Redistributions in binary form must reproduce the above copyright
11292915Sdim//   notice, this list of conditions and the following disclaimer in the
12292915Sdim//   documentation and/or other materials provided with the distribution.
13292915Sdim// * Neither the name of Google Inc. nor the names of its contributors
14292915Sdim//   may be used to endorse or promote products derived from this software
15292915Sdim//   without specific prior written permission.
16292915Sdim//
17292915Sdim// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18292915Sdim// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19292915Sdim// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20292915Sdim// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21292915Sdim// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22292915Sdim// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23292915Sdim// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24292915Sdim// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25292915Sdim// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26292915Sdim// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27292915Sdim// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28292915Sdim
29292915Sdim#include "utils/format/exceptions.hpp"
30292915Sdim
31292915Sdim#include <cstring>
32292915Sdim
33292915Sdim#include <atf-c++.hpp>
34292915Sdim
35292915Sdimusing utils::format::bad_format_error;
36292915Sdimusing utils::format::error;
37292915Sdimusing utils::format::extra_args_error;
38292915Sdim
39292915Sdim
40292915SdimATF_TEST_CASE_WITHOUT_HEAD(error);
41292915SdimATF_TEST_CASE_BODY(error)
42292915Sdim{
43292915Sdim    const error e("Some text");
44292915Sdim    ATF_REQUIRE(std::strcmp("Some text", e.what()) == 0);
45292915Sdim}
46292915Sdim
47292915Sdim
48292915SdimATF_TEST_CASE_WITHOUT_HEAD(bad_format_error);
49292915SdimATF_TEST_CASE_BODY(bad_format_error)
50292915Sdim{
51292915Sdim    const bad_format_error e("format-string", "the-error");
52292915Sdim    ATF_REQUIRE(std::strcmp("Invalid formatting string 'format-string': "
53292915Sdim                            "the-error", e.what()) == 0);
54292915Sdim    ATF_REQUIRE_EQ("format-string", e.format());
55292915Sdim}
56292915Sdim
57292915Sdim
58292915SdimATF_TEST_CASE_WITHOUT_HEAD(extra_args_error);
59292915SdimATF_TEST_CASE_BODY(extra_args_error)
60292915Sdim{
61292915Sdim    const extra_args_error e("fmt", "extra");
62292915Sdim    ATF_REQUIRE(std::strcmp("Not enough fields in formatting string 'fmt' to "
63292915Sdim                            "place argument 'extra'", e.what()) == 0);
64292915Sdim    ATF_REQUIRE_EQ("fmt", e.format());
65292915Sdim    ATF_REQUIRE_EQ("extra", e.arg());
66292915Sdim}
67292915Sdim
68292915Sdim
69292915SdimATF_INIT_TEST_CASES(tcs)
70292915Sdim{
71292915Sdim    ATF_ADD_TEST_CASE(tcs, error);
72292915Sdim    ATF_ADD_TEST_CASE(tcs, bad_format_error);
73292915Sdim    ATF_ADD_TEST_CASE(tcs, extra_args_error);
74292915Sdim}
75292915Sdim