Remove building with NOCRYPTO option
[minix.git] / external / bsd / libc++ / dist / libcxx / test / strings / string.conversions / stol.pass.cpp
blobd1cd75dcf175852ad4a14d817635adb2470aa286
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 // long stol(const string& str, size_t *idx = 0, int base = 10);
16 // long stol(const wstring& str, size_t *idx = 0, int base = 10);
18 #include <string>
19 #include <cassert>
21 int main()
23 assert(std::stol("0") == 0);
24 assert(std::stol(L"0") == 0);
25 assert(std::stol("-0") == 0);
26 assert(std::stol(L"-0") == 0);
27 assert(std::stol("-10") == -10);
28 assert(std::stol(L"-10") == -10);
29 assert(std::stol(" 10") == 10);
30 assert(std::stol(L" 10") == 10);
31 size_t idx = 0;
32 assert(std::stol("10g", &idx, 16) == 16);
33 assert(idx == 2);
34 idx = 0;
35 assert(std::stol(L"10g", &idx, 16) == 16);
36 assert(idx == 2);
37 idx = 0;
38 try
40 std::stol("", &idx);
41 assert(false);
43 catch (const std::invalid_argument&)
45 assert(idx == 0);
47 try
49 std::stol(L"", &idx);
50 assert(false);
52 catch (const std::invalid_argument&)
54 assert(idx == 0);
56 try
58 std::stol(" - 8", &idx);
59 assert(false);
61 catch (const std::invalid_argument&)
63 assert(idx == 0);
65 try
67 std::stol(L" - 8", &idx);
68 assert(false);
70 catch (const std::invalid_argument&)
72 assert(idx == 0);
74 try
76 std::stol("a1", &idx);
77 assert(false);
79 catch (const std::invalid_argument&)
81 assert(idx == 0);
83 try
85 std::stol(L"a1", &idx);
86 assert(false);
88 catch (const std::invalid_argument&)
90 assert(idx == 0);
92 // LWG issue #2009
93 try
95 std::stol("9999999999999999999999999999999999999999999999999", &idx);
96 assert(false);
98 catch (const std::out_of_range&)
100 assert(idx == 0);
104 std::stol(L"9999999999999999999999999999999999999999999999999", &idx);
105 assert(false);
107 catch (const std::out_of_range&)
109 assert(idx == 0);