Debian Codegraph @

packages/stk/stk_unit_tests/stk_util/environment/UnitTestDemangle.cpp

raw
1 // Copyright 2002 - 2008, 2010, 2011 National Technology Engineering
2 // Solutions of Sandia, LLC (NTESS). Under the terms of Contract
3 // DE-NA0003525 with NTESS, the U.S. Government retains certain rights
4 // in this software.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following
15 // disclaimer in the documentation and/or other materials provided
16 // with the distribution.
17 //
18 // * Neither the name of NTESS nor the names of its contributors
19 // may be used to endorse or promote products derived from this
20 // software without specific prior written permission.
21 //
22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34
35 #include "gtest/gtest.h"
36 #include "stk_util/diag/StringUtil.hpp" // for demangle
37 #include <string> // for operator==, string, basic_string
38 #include <typeinfo> // for type_info
39 #include <vector> // for vector
40
41
42 bool
43 utest_demangle()
44 {
45 return true;
46 }
47
48 TEST(UnitTestDemangle, UnitTest)
49 {
50 #if defined(__PGI)
51 {
52 std::string linux_name("ThisIsJunk");
53 std::string demangled_name = stk::demangle(linux_name.c_str());
54 ASSERT_EQ(linux_name, demangled_name);
55 }
56
57 {
58 std::string linux_name("bool ()");
59 std::string demangled_name = stk::demangle(typeid(utest_demangle).name());
60 ASSERT_EQ(linux_name, demangled_name);
61 }
62
63 {
64 std::vector<double> double_vector;
65
66 std::string linux_name("std::vector<double, std::allocator<double>>");
67 std::string demangled_name = stk::demangle(typeid(double_vector).name());
68 ASSERT_EQ(linux_name, demangled_name);
69 }
70
71 #elif defined(__xlC__)
72 {
73 std::string linux_name("ThisIsJunk");
74 std::string demangled_name = stk::demangle(linux_name.c_str());
75 // ASSERT_EQ((linux_name == demangled_name), true);
76 }
77
78 {
79 std::string linux_name("bool ()()");
80 std::string demangled_name = stk::demangle(typeid(utest_demangle).name());
81 // ASSERT_EQ(linux_name, demangled_name);
82 }
83
84 {
85 std::vector<double> double_vector;
86
87 std::string linux_name("std::vector<double, std::allocator<double> >");
88 std::string demangled_name = stk::demangle(typeid(double_vector).name());
89 // ASSERT_EQ((linux_name == demangled_name), true);
90 }
91 #elif defined(__linux__)
92 {
93 std::string linux_name("ThisIsJunk");
94 std::string demangled_name = sierra::demangle(linux_name.c_str());
95 ASSERT_EQ((linux_name == demangled_name), true);
96 }
97
98 {
99 std::vector<double> double_vector;
100
101 #ifdef _GLIBCXX_DEBUG
102 std::string linux_name("__gnu_debug_def::vector<double, std::allocator<double> >");
103 #else
104 std::string linux_name("std::vector<double, std::allocator<double> >");
105 #endif
106 std::string demangled_name = sierra::demangle(typeid(double_vector).name());
107 ASSERT_EQ((linux_name == demangled_name), true);
108 }
109 #endif
110 }