Remove building with NOCRYPTO option
[minix.git] / external / bsd / libc++ / dist / libcxx / test / strings / string.conversions / stoul.pass.cpp
blobfcd19e88355bceddf323a51bb4ad7a9490e59391
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 // XFAIL: with_system_lib=x86_64-apple-darwin11
11 // XFAIL: with_system_lib=x86_64-apple-darwin12
13 // <string>
15 // unsigned long stoul(const string& str, size_t *idx = 0, int base = 10);
16 // unsigned long stoul(const wstring& str, size_t *idx = 0, int base = 10);
18 #include <string>
19 #include <cassert>
21 int main()
23 assert(std::stoul("0") == 0);
24 assert(std::stoul(L"0") == 0);
25 assert(std::stoul("-0") == 0);
26 assert(std::stoul(L"-0") == 0);
27 assert(std::stoul(" 10") == 10);
28 assert(std::stoul(L" 10") == 10);
29 size_t idx = 0;
30 assert(std::stoul("10g", &idx, 16) == 16);
31 assert(idx == 2);
32 idx = 0;
33 assert(std::stoul(L"10g", &idx, 16) == 16);
34 assert(idx == 2);
35 idx = 0;
36 try
38 std::stoul("", &idx);
39 assert(false);
41 catch (const std::invalid_argument&)
43 assert(idx == 0);
45 try
47 std::stoul(L"", &idx);
48 assert(false);
50 catch (const std::invalid_argument&)
52 assert(idx == 0);
54 try
56 std::stoul(" - 8", &idx);
57 assert(false);
59 catch (const std::invalid_argument&)
61 assert(idx == 0);
63 try
65 std::stoul(L" - 8", &idx);
66 assert(false);
68 catch (const std::invalid_argument&)
70 assert(idx == 0);
72 try
74 std::stoul("a1", &idx);
75 assert(false);
77 catch (const std::invalid_argument&)
79 assert(idx == 0);
81 try
83 std::stoul(L"a1", &idx);
84 assert(false);
86 catch (const std::invalid_argument&)
88 assert(idx == 0);
90 // LWG issue #2009
91 try
93 std::stoul("9999999999999999999999999999999999999999999999999", &idx);
94 assert(false);
96 catch (const std::out_of_range&)
98 assert(idx == 0);
102 std::stoul(L"9999999999999999999999999999999999999999999999999", &idx);
103 assert(false);
105 catch (const std::out_of_range&)
107 assert(idx == 0);