Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
InputTraitsBad.cpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 //
46 // Test for Zoltan2::InputTraitsBad
47 
48 // This should only be used for this test - verifies bad forms do not compile
49 #define Z2_INVERT_STATIC_ASSERT_FOR_UNIT_TESTING
50 
51 #include <Zoltan2_InputTraits.hpp>
52 
54 
55 #define BEGIN_CHECK if( InputTraits<
56 #define END_CHECK >::name() == "unused string" ) \
57  { std::cout << "Unused - Just make sure it compiles." << std::endl; }
58 
59 template< class A, class B, class C >
60 class SomeBadType {
61 public: SomeBadType() {}
62 };
63 
64 int main(int argc, char *argv[])
65 {
66  // makes a general list of 'bad' types - generally just check these all
67  // would fail - the #define above inverts the status of the static_asserts
68  // that means these should all compile but only in this test and nowhere else
69 
70  // scalar ordinal (first slot) must be float, double, or int
71  // this validates we would fail for any
83 
84  // local ordinal (second slot) must always be signed
85  // this validates that we would fail for any unsigned setting
98 
99  // global ordinal (third slot) must be int, long, long long, ssize_t,
100  // unsigned int, unsigned long, unsigned long long, size_t
107 
108  // we also want to make sure that user typedefs will work just fine
109  // lots of redundancy here to make sure std::is_same is working as we think
110  typedef signed int user_int_t;
111  typedef unsigned int user_unsigned_int_t;
112  typedef float user_float_t;
113  typedef double user_double_t;
114  typedef uint32_t user_uint32_t;
115  typedef int64_t user_int64_t;
116  typedef uint64_t user_uint64_t;
117  typedef signed long user_long_t;
118  typedef signed long long user_long_long_t;
119  typedef unsigned long user_unsigned_long_t;
120  typedef unsigned long long user_unsigned_long_long_t;
121  typedef size_t user_size_t;
122  typedef ssize_t user_ssize_t;
123  typedef SomeBadType<int,int, int> user_some_bad_t;
124 
125  // scalar ordinal (first slot) must be float, double, or int
140 
141  // local ordinal (second slot) must always be signed
153 
154  // global ordinal (third slot) must be int, long, long long, ssize_t,
155  // unsigned int, unsigned long, unsigned long long, size_t
160 
161 
162  // some more checks that should all fail - this doesn't check all
163  // combinations but just tries a bunch of things on different class types
169  BEGIN_CHECK Xpetra::CrsMatrix<double, float, long long> END_CHECK
170  BEGIN_CHECK Xpetra::CrsMatrix<float, long, float> END_CHECK
171  BEGIN_CHECK Xpetra::CrsMatrix<float, double, unsigned long> END_CHECK
172  BEGIN_CHECK Xpetra::CrsMatrix<float, unsigned long, double> END_CHECK
173  BEGIN_CHECK Xpetra::CrsMatrix<long long, long long, unsigned int> END_CHECK
174  BEGIN_CHECK Tpetra::CrsMatrix<SomeBadType<int, int, int>, int, long long> END_CHECK
175  BEGIN_CHECK Xpetra::CrsGraph<int, SomeBadType<int, double, float>> END_CHECK
176  BEGIN_CHECK Xpetra::CrsGraph<SomeBadType<int, long long, int>, unsigned int> END_CHECK
177  BEGIN_CHECK Xpetra::CrsGraph<int, double> END_CHECK
178 
179  // set the PASS keyword
180  std::cout << "Validated bad InputTraits - The test PASSED because it "
181  "compiled with the static_assert checks inverted." << std::endl;
182  return 0;
183 }
184 
int main(int narg, char *arg[])
#define END_CHECK
A simple class that can be the User template argument for an InputAdapter.
The traits required of User input classes or structures.
#define BEGIN_CHECK
Traits for application input objects.