pointer.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// <string>
11
12// int compare(const charT *s) const;
13
14#include <string>
15#include <cassert>
16
17int sign(int x)
18{
19    if (x == 0)
20        return 0;
21    if (x < 0)
22        return -1;
23    return 1;
24}
25
26template <class S>
27void
28test(const S& s, const typename S::value_type* str, int x)
29{
30    assert(sign(s.compare(str)) == sign(x));
31}
32
33typedef std::string S;
34
35int main()
36{
37    test(S(""), "", 0);
38    test(S(""), "abcde", -5);
39    test(S(""), "abcdefghij", -10);
40    test(S(""), "abcdefghijklmnopqrst", -20);
41    test(S("abcde"), "", 5);
42    test(S("abcde"), "abcde", 0);
43    test(S("abcde"), "abcdefghij", -5);
44    test(S("abcde"), "abcdefghijklmnopqrst", -15);
45    test(S("abcdefghij"), "", 10);
46    test(S("abcdefghij"), "abcde", 5);
47    test(S("abcdefghij"), "abcdefghij", 0);
48    test(S("abcdefghij"), "abcdefghijklmnopqrst", -10);
49    test(S("abcdefghijklmnopqrst"), "", 20);
50    test(S("abcdefghijklmnopqrst"), "abcde", 15);
51    test(S("abcdefghijklmnopqrst"), "abcdefghij", 10);
52    test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", 0);
53}
54