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, int, or long long
71  // this validates we would fail for any
82 
83  // local ordinal (second slot) must always be signed
84  // this validates that we would fail for any unsigned setting
97 
98  // global ordinal (third slot) must be int, long, long long, ssize_t,
99  // unsigned int, unsigned long, unsigned long long, size_t
106 
107  // we also want to make sure that user typedefs will work just fine
108  // lots of redundancy here to make sure std::is_same is working as we think
109  typedef signed int user_int_t;
110  typedef unsigned int user_unsigned_int_t;
111  typedef float user_float_t;
112  typedef double user_double_t;
113  typedef uint32_t user_uint32_t;
114  typedef uint64_t user_uint64_t;
115  typedef signed long user_long_t;
116  typedef unsigned long user_unsigned_long_t;
117  typedef unsigned long long user_unsigned_long_long_t;
118  typedef size_t user_size_t;
119  typedef SomeBadType<int,int, int> user_some_bad_t;
120 
121  // scalar ordinal (first slot) must be float, double, or int
132 
133  // local ordinal (second slot) must always be signed
145 
146  // global ordinal (third slot) must be int, long, long long, ssize_t,
147  // unsigned int, unsigned long, unsigned long long, size_t
152 
153 
154  // some more checks that should all fail - this doesn't check all
155  // combinations but just tries a bunch of things on different class types
158  BEGIN_CHECK Xpetra::CrsMatrix<double, float, long long> END_CHECK
159  BEGIN_CHECK Xpetra::CrsMatrix<float, long, float> END_CHECK
160  BEGIN_CHECK Xpetra::CrsMatrix<float, double, unsigned long> END_CHECK
161  BEGIN_CHECK Xpetra::CrsMatrix<float, unsigned long, double> END_CHECK
162  BEGIN_CHECK Tpetra::CrsMatrix<SomeBadType<int, int, int>, int, long long> END_CHECK
163  BEGIN_CHECK Xpetra::CrsGraph<int, SomeBadType<int, double, float>> END_CHECK
164  BEGIN_CHECK Xpetra::CrsGraph<SomeBadType<int, long long, int>, unsigned int> END_CHECK
165  BEGIN_CHECK Xpetra::CrsGraph<int, double> END_CHECK
166 
167  // set the PASS keyword
168  std::cout << "Validated bad InputTraits - The test PASSED because it "
169  "compiled with the static_assert checks inverted." << std::endl;
170  return 0;
171 }
172 
#define END_CHECK
A simple class that can be the User template argument for an InputAdapter.
int main(int narg, char **arg)
Definition: coloring1.cpp:199
The traits required of User input classes or structures.
#define BEGIN_CHECK
Traits for application input objects.