ctor_char_pointer_error_code.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <ios>
11
12// class ios_base::failure
13
14// explicit failure(const char* msg, const error_code& ec = io_errc::stream);
15
16#include <ios>
17#include <string>
18#include <cassert>
19
20int main()
21{
22    {
23        std::string what_arg("io test message");
24        std::ios_base::failure se(what_arg.c_str(), make_error_code(std::errc::is_a_directory));
25        assert(se.code() == std::make_error_code(std::errc::is_a_directory));
26        std::string what_message(se.what());
27        assert(what_message.find(what_arg) != std::string::npos);
28        assert(what_message.find("Is a directory") != std::string::npos);
29    }
30    {
31        std::string what_arg("io test message");
32        std::ios_base::failure se(what_arg.c_str());
33        assert(se.code() == std::make_error_code(std::io_errc::stream));
34        std::string what_message(se.what());
35        assert(what_message.find(what_arg) != std::string::npos);
36        assert(what_message.find(std::iostream_category().message(static_cast<int>
37            (std::io_errc::stream))) != std::string::npos);
38    }
39}
40